package com.frank.code_notes.C01_array;

import cn.hutool.core.lang.Console;

/**
 * @Description 367.有效的完全平方数
 * @Author zhoujr
 * @Data 2024/11/25 15:01
 */
public class L367ValidPerfectSquareNum {

    /**
     * @Description 使用二分法
     */
    public static boolean isPerfectSquare(int num) {
        int left = 0, right = num;
        while (left <= right) {
            int mid = left + ((right - left) >> 1);
            if (mid * mid == num) {
                return Boolean.TRUE;
            } else if ((long)mid * mid > num) {
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        return Boolean.FALSE;
    }

    public static void main(String[] args) {
        Console.log(isPerfectSquare(2147483647));
    }

}
